package com.ehuoyun.ecstore.action;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.StreamingResolution;
import net.sourceforge.stripes.integration.spring.SpringBean;

import com.ehuoyun.ecstore.biz.CompanyMgr;
import com.ehuoyun.ecstore.model.Company;

public class CompanyActionBean extends AbstractActionBean {
    @SpringBean
    private CompanyMgr companyMgr;
    
    private String companyName;
    
    private Company company;
    
    private Boolean isAdCompany;
    
    private List<Company> companies;
    
    public Resolution ajaxFind() {
   		companies = companyMgr.search(companyName);
		return new ForwardResolution("/includes/search-results.jsp");
    }    
    
    public Resolution ajaxSave() {
    	company.setOwner(1L);
    	companyMgr.save(company);
        return new StreamingResolution("") {
        	protected void stream(HttpServletResponse response) throws Exception {
                String str = "{id:" + company.getId()
                	+ ", name:'" + company.getName() + "'}";
                response.getOutputStream().write(str.getBytes("UTF-8"));
            }
        };
    }

	public String getCompanyName() {
		return companyName;
	}

	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}

	public Company getCompany() {
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

	public List<Company> getCompanies() {
		return companies;
	}

	public void setCompanies(List<Company> companies) {
		this.companies = companies;
	}

	public Boolean getIsAdCompany() {
		return isAdCompany;
	}

	public void setIsAdCompany(Boolean isAdCompany) {
		this.isAdCompany = isAdCompany;
	}
}
